* Bootstrap procedure over entire causal link:
capture program drop layersbootstrap
program define layersbootstrap, rclass

	preserve
	bsample , cluster(firmcode) idcluster(newfirmcode)
	
	sort newfirmcode t
	xtset newfirmcode t

	* First stage identical for all cases:
	cap drop industryyear
	egen industryyear = group(sector009 year) if sample == 1
	cap drop indyeardummy*
	quietly tab industryyear, gen(indyeardummy)
	xtreg logsales I_WID I_transport_f2 indyeardummy* if sample == 1, fe
	cap drop logsalespred
	predict logsalespred, xbu
	
	* GMM, ma(1) errors, one-step
	cap drop industryyear
	egen industryyear = group(year sector009) if sample == 1 ///
	& L.layers != . & year != 2000 & sector009 != 2
	cap drop indyeardummy*
	quietly tab industryyear, gen(indyeardummy)
	xtabond2 layers L.layers logsalespred sectordummy1-sectordummy8 yeardummy4-yeardummy12 if sample == 1, ///
	gmmstyle(L.layers, lag(3 .)) gmmstyle(logsalespred, lag(4 .)) robust
	return scalar layers_ivind = _b[L.layers]
	return scalar sales_ivind = _b[logsalespred]
	cap drop layers_ivind_all
	predict layers_ivind_all
	
	areg log2inequality1 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality1_ivind = _b[layers_ivind_all]
	areg log2inequality2 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality2_ivind = _b[layers_ivind_all]
	areg log2inequality4 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality4_ivind = _b[layers_ivind_all]
	areg log2inequality5 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality5_ivind = _b[layers_ivind_all]
	areg wagegap1_topbottom_log layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_log_ivind = _b[layers_ivind_all]
	
	areg res2inequality1_model2 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_ivind = _b[layers_ivind_all]
	areg res2inequality2_model2 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_ivind = _b[layers_ivind_all]
	areg res2inequality4_model2 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_ivind = _b[layers_ivind_all]
	areg res2inequality5_model2 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_ivind = _b[layers_ivind_all]
	areg wagegap1_topbottom_res2 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res2_ivind = _b[layers_ivind_all]
	
	areg res2inequality1_model4 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_ivind_v2 = _b[layers_ivind_all]
	areg res2inequality2_model4 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_ivind_v2 = _b[layers_ivind_all]
	areg res2inequality4_model4 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_ivind_v2 = _b[layers_ivind_all]
	areg res2inequality5_model4 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_ivind_v2 = _b[layers_ivind_all]
	areg wagegap1_topbottom_res4 layers_ivind_all indyeardummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res4_ivind_v2 = _b[layers_ivind_all]
	
	restore
end
